package com.cjh.wxdemoserver.peopel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjh.wxdemoserver.base.result.Result;
import com.cjh.wxdemoserver.peopel.dto.PeopelQueryDTO;
import com.cjh.wxdemoserver.peopel.dto.PeopleSexChartDataDTO;
import com.cjh.wxdemoserver.peopel.entity.Peopel;
import com.cjh.wxdemoserver.peopel.service.PeopelService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ChenJH
 * @description Peopel控制层
 */

@RestController
@RequestMapping("/peopel" )
public class PeopelController {
    @Resource
    private PeopelService peopelService;

    @GetMapping("/page")
    public Result<Page<Peopel>> page(Page<Peopel> page, PeopelQueryDTO peopelQueryDTO) {
        return Result.ok(peopelService.page(page, peopelQueryDTO));
    }

    @GetMapping("/{id}")
    public Result<Peopel> getById(@PathVariable("id") Long id) {
        return Result.ok(peopelService.getById(id));
    }

    @PostMapping
    public Result<Void> add(@RequestBody Peopel peopel) {
        peopelService.add(peopel);
        return Result.ok();
    }

    @PutMapping
    public Result<Void> update(@RequestBody Peopel peopel) {
        peopelService.update(peopel);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable("id") Long id) {
        peopelService.delete(id);
        return Result.ok();
    }

    @GetMapping("/getSexChartData")
    public Result<List<PeopleSexChartDataDTO>> getSexChartData() {
        return Result.ok(peopelService.getSexChartData());
    }
}
